﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Incendios0_1.user_managment;
using System.Diagnostics;
using Incendios0_1.Camera.camera_management;

namespace Incendios0_1.authentication
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            textBox1.Focus();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            authenticate();
        }

        private void authenticate()
        {
            if (UserControler.SearchUserbyUserAndPassword(textBox1.Text, textBox2.Password) != null)
            {
                DialogResult = true;
                this.Close();
            }
            else
            {
                Microsoft.Windows.Controls.MessageBox.Show("Nombre de usuario o contraseña incorrectos", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                textBox2.Focus();
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                authenticate();
        }

        private void AccountAdministration_Click(object sender, RoutedEventArgs e)
        {
            if (UserControler.SearchUserbyUserAndPassword(textBox1.Text, textBox2.Password) != null)
            {
                new Usermanagment().ShowDialog();
            }
            else
                Microsoft.Windows.Controls.MessageBox.Show("Nombre de usuario o contraseña incorrectos", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
        }

        private void CamAdministration_Click(object sender, RoutedEventArgs e)
        {
            if (UserControler.SearchUserbyUserAndPassword(textBox1.Text, textBox2.Password) != null)
            {
                new Cameramanagement().ShowDialog();
            }
            else
                Microsoft.Windows.Controls.MessageBox.Show("Nombre de usuario o contraseña incorrectos", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            new Configure().ShowDialog();
            textBox1.Focus();
        }
    }
}
